﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OnTheWay.Command;
using System.Windows;
using System.ComponentModel;

namespace OnTheWay.Functions
{
    [DesignTimeVisible(false)]
    public class FunctionCtrlCmd : FunctionCtrl
    {
        public FunctionCtrlCmd()
        {
            this.CommandSave = new DelegateCommand(OnCommandSave,OnCanCommandSave, "Save", "保存");
            this.CommandAdd = new DelegateCommand(OnCommandAdd,OnCanCommandAdd, "Add", "添加");
            this.CommandRefresh = new DelegateCommand(OnCommandRefresh,OnCanCommandRefresh, "Refresh", "刷新");
            this.CommandDelete = new DelegateCommand(OnCommandDelete,OnCanCommandDelete, "Delete", "删除");
            this.CommandSelect = new DelegateCommand(OnCommandSelect,OnCanCommandSelect, "Select", "选择");
            this.CommandModify = new DelegateCommand(OnCommandModify,OnCanCommandModify, "Modify", "修改");
            this.CommandMinSize = new DelegateCommand(OnCommandMinSize,OnCanCommandMinSize, "MinSize", "最小化");
            this.CommandClose = new DelegateCommand(OnCommandClose,OnCanCommandClose, "Close", "关闭");
            this.CommandCancel = new DelegateCommand(OnCommandCancel,this.OnCanCommandCancel, "Cancel", "取消");
        }

        #region 命令及默认处理逻辑

        #region 刷新
        /// <summary>
        /// 刷新命令
        /// </summary>
        public DelegateCommand CommandRefresh { get; set; }
        /// <summary>
        /// 刷新命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandRefresh(object obj)
        { }
        /// <summary>
        /// 新建命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandRefresh(object obj)
        {
            return true;
        }
        #endregion 刷新

        #region 保存
        /// <summary>
        /// 保存命令
        /// </summary>
        public DelegateCommand CommandSave { get; set; }
        /// <summary>
        /// 保存命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandSave(object obj)
        {

        }
        /// <summary>
        /// 保存命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandSave(object obj)
        {
            return true;
        }
        #endregion 保存

        #region 新建
        /// <summary>
        /// 新建命令
        /// </summary>
        public DelegateCommand CommandAdd { get; set; }
        /// <summary>
        /// 新建命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandAdd(object obj)
        {

        }
        /// <summary>
        /// 新建命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandAdd(object obj)
        {
            return true;
        }
        #endregion 新建

        #region 删除
        /// <summary>
        /// 删除命令
        /// </summary>
        public DelegateCommand CommandDelete { get; set; }
        /// <summary>
        /// 删除命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandDelete(object obj)
        {

        }
        /// <summary>
        /// 删除命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandDelete(object obj)
        {
            return true;
        }
        #endregion 删除

        #region 选择
        /// <summary>
        /// 选着命令
        /// </summary>
        public DelegateCommand CommandSelect { get; set; }
        /// <summary>
        /// 选择命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandSelect(object obj)
        {
        }
        /// <summary>
        /// 选择命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandSelect(object obj)
        {
            return true;
        }
        #endregion 选择

        #region 修改
        /// <summary>
        /// 修改命令
        /// </summary>
        public DelegateCommand CommandModify { get; set; }
        /// <summary>
        /// 修改命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandModify(object obj)
        {

        }
        /// <summary>
        /// 修改命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandModify(object obj)
        {
            return true;
        }
        #endregion 修改

        #region 最小化
        /// <summary>
        /// 最小化命令
        /// </summary>
        public DelegateCommand CommandMinSize { get; set; }
        /// <summary>
        /// 最小化命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandMinSize(object obj)
        {
            Window window = ParentWindow;
            if (null != window)
            { window.WindowState = WindowState.Minimized; }
        }
        /// <summary>
        /// 最小化命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandMinSize(object obj)
        {
            return true;
        }
        #endregion 最小化

        #region 关闭
        /// <summary>
        /// 关闭命令
        /// </summary>
        public DelegateCommand CommandClose { get; set; }
        /// <summary>
        /// 关闭命令处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandClose(object obj)
        {
            if (base.IFunPanel != null)
            {
                base.IFunPanel.CloseFunction(this);
            }
        }
        /// <summary>
        /// 关闭命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandClose(object obj)
        {
            return true;
        }
        #endregion 关闭

        #region 取消
        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CommandCancel { get; set; }
        /// <summary>
        /// 关闭命令默认处理逻辑
        /// </summary>
        /// <param name="obj"></param>
        protected virtual void OnCommandCancel(object obj)
        {
        }
        /// <summary>
        /// 取消命令是否可执行
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected virtual bool OnCanCommandCancel(object obj)
        {
            return true;
        }
        #endregion 取消

        #endregion 命令及处理逻辑

    }
}
